package org.gdpi.controller;

import org.gdpi.bean.Manager;
import org.gdpi.bean.Student;
import org.gdpi.bean.Teacher;
import org.gdpi.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@Controller
public class LoginController {
    @Resource
    private LoginService loginService;

    @RequestMapping("/toLogin")
    public  String tologin(){
        return "include/login";
    }

    @RequestMapping("/login")
    public String login(Integer type, String username, String password, HttpSession session){
        if(type==0){
            Student student =loginService.loginByStudent(username,password);
            return "student/student";
        }
        else if(type==1){
            Teacher teacher = loginService.loginByTeacher(username,password);
            return "teacher/teacher";
        }
        else if(type==2){
            Manager manager=loginService.loginByManager(username,password);
            session.setAttribute("user",manager);
            return "redirect:m/index";
        }
        return "redirect:toLogin";
    }

    @RequestMapping("/edit")
    public String edit(HttpSession session){
        session.invalidate();
        return "redirect:toLogin";
    }
}
